#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn];
vector<LL>g[maxn];
bool vis[maxn];
LL maxv=0;
LL dfs(LL u){
    vis[u]=true;
    LL siz=1;
    maxv=max(maxv,a[u]);
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(vis[v]) continue;
        siz+=dfs(v);
    }
    return siz;
}
int main(void)
{
  LL n,m;n=read();m=read();
  for(LL i=1;i<=n;i++){
     a[i]=read();
  }
  for(LL i=1;i<=m;i++){
    LL u,v;u=read();v=read();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  LL ans=0;
  for(LL i=1;i<=n;i++){
    if(!vis[i]){
        maxv=0;
        LL siz=dfs(i);
        ans+=siz*maxv;
    }
  }
  printf("%lld\n",ans);
return 0;
}
